package com.che.libcommon.utils;

import android.content.Intent;
import android.net.Uri;
import com.blankj.utilcode.util.AppUtils;

public final class MapUtils {

  private static final String[] pkgs = {"com.baidu.BaiduMap", "com.autonavi.minimap",
      "com.google.android.apps.maps"};


  public static Intent queryNavigation(double lat, double lon) {

    String pkg = "com.baidu.BaiduMap";
    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_VIEW);
    intent.addCategory(Intent.CATEGORY_DEFAULT);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    if (AppUtils.isAppInstalled(pkg)) {

      intent.setPackage(pkg);
      intent.setData(Uri.parse("baidumap://map/navi?location=" + lat + "," + lon));

      return intent;
    }

    pkg = "com.autonavi.minimap";
    if (AppUtils.isAppInstalled(pkg)) {

      intent.setPackage(pkg);
      intent.setData(Uri.parse("androidamap://navi?sourceApplication=12123查违章&dev=1&style=2&lat="+lat+"&lon="+lon));

      return intent;
    }

    pkg = "com.google.android.apps.maps";

    if(AppUtils.isAppInstalled(pkg)){
      intent.setData(Uri.parse("google.navigation:q="+lat+","+lon));
      intent.setPackage(pkg);

      return intent;
    }
    intent.setData(Uri.parse("geo:"+lat+","+lon));
    return intent;
  }

}
